package cn.iocoder.yudao.module.wine.controller.app.stockinfo;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.module.wine.controller.app.stockinfo.vo.*;
import cn.iocoder.yudao.module.wine.dal.dataobject.stockinfo.StockInfoDO;
import cn.iocoder.yudao.module.wine.service.stockinfo.StockInfoService;

import java.util.List;

@Tag(name = "用户 APP - 出入库信息")
@RestController
@RequestMapping("/wine/stock-info")
@Validated
public class AppStockInfoController {

    @Resource
    private StockInfoService stockInfoService;

    @PostMapping("/create")
    @Operation(summary = "创建出入库信息")
    public CommonResult<Long> createStockInfo(@Valid @RequestBody AppStockInfoSaveReqVO createReqVO) {
        return success(stockInfoService.appCreateStockInfo(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新出入库信息")
    public CommonResult<Boolean> updateStockInfo(@Valid @RequestBody AppStockInfoSaveReqVO updateReqVO) {
        return success(stockInfoService.appUpdateStockInfo(updateReqVO));
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除出入库信息")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteStockInfo(@RequestParam("id") Long id) {
        stockInfoService.deleteStockInfo(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得出入库信息")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<AppStockInfoRespVO> getStockInfo(@RequestParam("id") Long id) {
        StockInfoDO stockInfo = stockInfoService.getStockInfo(id);
        return success(BeanUtils.toBean(stockInfo, AppStockInfoRespVO.class));
    }

    @GetMapping("/list")
    @Operation(summary = "获得出入库信息列表")
    public CommonResult<List<AppStockInfoRespVO>> getStockInfoList(@Valid AppStockInfoListReqVO reqVO) {
        List<AppStockInfoRespVO> list = stockInfoService.getStockInfoList(reqVO);
        return success(list);
    }


}
